home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / btwalker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.8 KB  |  102 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: btwalker.h
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer   
  8. // File Creation Date: 12/02/1998 
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The BtreeWalkerb class defines a generic iterator used to walk
  32. through balanced multi-way file-base trees. The BtreeWalker
  33. class is a general-purpose class used to sort the entry keys
  34. and perform search operations.
  35. */
  36. // ----------------------------------------------------------- //   
  37. #ifndef __BTWALKER_HPP
  38. #define __BTWALKER_HPP
  39.  
  40. #include "btree.h"
  41. #include "queue.h"  
  42. #include "dllist.h"
  43.  
  44. enum BtreeWalkOrder {
  45.   btPREORDER,  // Visit Root first, then Left, then Right subtree 
  46.   btPOSTORDER, // Visit Left subtree first, then Right, then Root 
  47.   btINORDER,   // Visit Left subtree first, then Root, then Right 
  48.   btLVLORDER   // Visit (L)evel by (L)evel, start at Root, and go Left to Right
  49. };
  50.  
  51. class BtreeWalkerb
  52. {
  53. public:
  54.   BtreeWalkerb(Btree *t, BtreeWalkOrder w); 
  55.   virtual ~BtreeWalkerb() { }
  56.  
  57. public:
  58.   void Reset() { Reset(tree, worder); }
  59.   void Reset(Btree *t, BtreeWalkOrder w); 
  60.   CachePointer Next() { return (this->*NextFptr)(); }
  61.   
  62. protected:
  63.   CachePointer (BtreeWalkerb::*NextFptr)(); // Pointer to member function
  64.   CachePointer NextPreOrder();
  65.   CachePointer NextInOrder();
  66.   CachePointer NextPostOrder();
  67.   CachePointer NextLvlOrder();
  68.   
  69. protected:
  70.   Queue<__LWORD__> path;       // Current path of parents through the tree
  71.   Queue<__LWORD__> right_path; // Current path of right parents 
  72.   Btree *tree;                 // Pointer to the B-tree
  73.   CachePointer root;           // Start of the B-tree being iterated
  74.   CachePointer curr;           // Current node being traversed
  75.   int state;                   // Holds up or down state indication 
  76.   BtreeWalkOrder worder;       // Enumerated type of WalkOrder 
  77. };
  78.  
  79. // The visit action defines a procedure used to process entry keys.
  80. typedef void (*EntryKeyVisitFunc)(EntryKey &e); 
  81.  
  82. class BtreeWalker 
  83. {
  84. public:
  85.   BtreeWalker(Btree *t) { btx = t; }
  86.   ~BtreeWalker() { }
  87.  
  88. public:
  89.   unsigned Sort(EntryKeyVisitFunc Visit);
  90.   int Find(const EntryKey &key, EntryKey &e);
  91.   unsigned Partiallookup(const char *p, EntryKeyVisitFunc Visit);
  92.  
  93. private:
  94.   Btree *btx; // Pointer to the currently open B-tree
  95. };
  96.  
  97. #endif // __BTWALKER_HPP
  98. // ----------------------------------------------------------- // 
  99. // ------------------------------- //
  100. // --------- End of File --------- //
  101. // ------------------------------- //
  102.